package com.four.seckill.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.four.seckill.entity.Allocation;
import com.four.seckill.feign.ShopFeignService;
import com.four.seckill.service.IAllocationService;
import com.four.seckill.vo.Allocation2Vo;
import com.four.seckill.vo.AllocationVo;
import com.guli.common.utils.R;
import com.guli.common.vo.ManageVo;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author gs
 * @since 2021-12-19
 */
@RestController
@RequestMapping("/seckill/allocation")
public class AllocationController {

    @Autowired
    private IAllocationService allocationService;
    @Autowired
    private ShopFeignService service;

    /**
     * 列表分页模糊
     * @param page
     * @param pageSize
     * @param vo
     * @return
     */

    @PostMapping("/findAll")
    public R findAllocationAll(
            @RequestParam(value = "page",defaultValue = "1")Integer page,
            @RequestParam(value = "size",defaultValue = "3")Integer pageSize,
            @RequestBody AllocationVo vo
            ){

        IPage<Allocation> find =  allocationService.findAll(page,pageSize,vo);
        
        return R.ok().put("list",find);
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById/{id}")
    public R deleteById(@PathVariable("id") Integer id){

        allocationService.deleteById(id);

        return R.ok();
    }

    /**
     * 添加
     * @param vo
     * @return
     */
    @PostMapping("save")
    public R save(@RequestBody Allocation2Vo vo){

        allocationService.addAll(vo);

        return R.ok();
    }

    /**
     * 修改秒杀配置
     * @param vo
     * @return
     */

    @PutMapping("update")
    public R update(@RequestBody Allocation2Vo vo){

        allocationService.updateAllocation(vo);
        return R.ok();
    }

    @GetMapping("/findAllManage")
    public List<ManageVo> findAllManage(){
        return service.findAllManage();
    }


}
